<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>评价回复</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../css/oksub.css">
    <script type="text/javascript" src="../../lib/loading/okLoading.js"></script>
</head>
<style>
    img {
        width: 100px;
        height: 100px;
    }
    textarea{
        width: 1000px;
        height: 100px;
    }
</style>
</style>
<body>
<div class="ok-body" id="app">
    <!--form表单-->
    <form class="layui-form ok-form" lay-filter="filter">

        <div class="layui-form-item">
            <label class="layui-form-label">ID</label>
            <div class="layui-input-block">
                <input type="text" name="id" id="id" v-model="id" autocomplete="off"
                       class="layui-input"
                       lay-verify="required" readonly>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">用户昵称</label>
            <div class="layui-input-block">
                <input type="text" name="nickname" id="nickname" v-model="nickname"
                       autocomplete="off"
                       class="layui-input"
                       lay-verify="required" readonly>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">评价的菜品</label>
            <div class="layui-input-block">
                <input type="text" name="food_name" id="food_name" v-model="food_name"
                       autocomplete="off"
                       class="layui-input"
                       lay-verify="required" readonly>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">评价的菜品</label>
            <div class="layui-input-block">
                <textarea type="text" name="review_text" id="review_text" v-model="review_text" readonly></textarea>
            </div>
        </div>

        <div class="layui-form-item" v-if="review_image_url">
            <label class="layui-form-label">评价图片</label>
            <div class="layui-input-block">
                <img :src="review_image_url" >
            </div>
        </div>



        <div class="layui-form-item">
            <label class="layui-form-label">评价回复</label>
            <div class="layui-input-block">
<!--                <input type="text" name="reply_text" id="reply_text" v-model="reply_text"-->
<!--                       autocomplete="off"-->
<!--                       class="layui-input"-->
<!--                       lay-verify="required">-->
                <textarea type="text" name="reply_text" id="reply_text" v-model="reply_text" ></textarea>
            </div>
        </div>


        <div class="layui-form-item">
            <div class="layui-input-block">
                <input class="layui-btn" value="确定" @click="update">
            </div>
        </div>


    </form>
</div>
<!--js逻辑-->
<script src="../../lib/layui/layui.js"></script>
<script src="vue.js"></script>
<script src="axios.js"></script>
<script>
    // 获取 URL 中的参数
    function getUrlParameter(name) {
        name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
        var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
        var results = regex.exec(location.search);
        return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
    }

    let initData;

    function initForm(data) {
        let jsonString = JSON.stringify(data);
        initData = JSON.parse(jsonString);
    }

    layui.use(["element", "form", "laydate", "okLayer", "okUtils"], function () {
        let form = layui.form;
        let laydate = layui.laydate;
        let okLayer = layui.okLayer;
        let okUtils = layui.okUtils;
        okLoading.close();
        form.val("filter", initData);
        laydate.render({elem: "#birthday", type: "datetime"});
        form.verify({
            birthdayVerify: [/^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))(\s(([01]\d{1})|(2[0123])):([0-5]\d):([0-5]\d))?$/, '日期格式不正确']
        });
        // form.on("submit(edit)", function (data) {
        //     okUtils.ajax("../../food.action?op=update", "post", data.field
        //         , true).done(function (response) {
        //         console.log(response);
        //         okLayer.greenTickMsg("修改成功", function () {
        //             parent.layer.close(parent.layer.getFrameIndex(window.name));
        //         });
        //     }).fail(function (error) {
        //         console.log(error)
        //     });
        //     return false;
        // });
    })

    var app = new Vue({
        el: "#app",
        data: {
            nickname:"",
            food_name: '',
            review_text:"",
            reply_text:"",
            id: '',
            review_image_url: '',
        },
        methods: {
            update() {
                var params=new URLSearchParams();
                params.append("id",this.id);
                params.append("nickname",this.nickname);
                params.append("reply_text",this.reply_text);
                axios.post("../../reviews.action?op=reviewReturn",params).then(result=>{
                    var jsonmodel=result.data;
                    if (jsonmodel.code===1){
                        alert("回复成功");
                        parent.layer.close(parent.layer.getFrameIndex(window.name));
                    }else {
                        alert("回复失败");
                    }
                })
            }
        },
        mounted(){
            var id = getUrlParameter("id");
            var params=new URLSearchParams();
            params.append("id",id);
            axios.post("../../reviews.action?op=getreview",params).then(result=>{
                var jsonmodel=result.data;
                if (jsonmodel.code===1){
                    var obj=jsonmodel.obj;
                    this.id=obj.id;
                    this.review_image_url=obj.review_image_url;
                    this.nickname=obj.nickname;
                    this.food_name=obj.food_name
                    this.review_text=obj.review_text;
                }
            })
        }
    })

</script>
</body>
</html>
